package com.gosophia.roleManagement.action;

import java.net.URLEncoder;

import net.sf.json.JSONArray;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.commons.web.bean.RequestResult;
import com.gosophia.userManagement.dto.RoleDTO;
import com.gosophia.userManagement.ws.UserManagementWebService;
import com.opensymphony.xwork2.ActionContext;

@Scope("prototype")
@Controller("GetRoleAction")
public class GetRoleAction extends BaseSupportAction{

	private String flag = "detail";
	
	private RoleDTO role;
	 
	private String permissionTree;
	
	@Autowired
	private UserManagementWebService userManagementWebService;

	@Override
	public String _execute() throws Exception {
		role = userManagementWebService.findRoleByRoleId(role.getRoleId());
		if (role != null) {
			permissionTree = JSONArray.fromObject(role.getPermissionDTOs()).toString().replace(
					"\"", "\\\"");
			super.getRequestResult().setRsltCode("0");
			if ("detail".equals(flag)) {
				return SUCCESS;
			} else {
				return "EDIT";
			}
		} else {
			if ("detail".equals(flag)){
				return SUCCESS;
			}else{
				super.getRequestResult().setRsltCode("1");
				super.getRequestResult().setMessage("该数据已删除！");
				ActionContext.getContext().getSession().put("_lastOpResult", super.getRequestResult());
				return "NODETAIL";
			}
			
		}
		
	}

	public void setRole(RoleDTO role) {
		this.role = role;
	}

	public RoleDTO getRole() {
		return role;
	}

	public void setPermissionTree(String permissionTree) {
		this.permissionTree = permissionTree;
	}

	public String getPermissionTree() {
		return permissionTree;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}

	public String getFlag() {
		return flag;
	}

}
